#{extends 'head.html' /}
#{ set title:'蓝莲花 | 订单1'/}
<link rel="stylesheet" href="/public/stylesheets/alert.css" type="text/css"></link>
<script type="text/javascript" src="/public/javascripts/adu.alert.js"></script>
<style type="text/css">
	div.main_frame {
		height: auto;
		margin: auto;
		overflow: hidden;
		width: 980px;
	}
	td, p, li, select, input, textarea, div {
		font-size: 12px;
	}
	ul, ol, li, p, h1, h2, h3, h4, h5, h6, form, fieldset, table, img, div {
		border: 0 none;
		margin: 0;
		padding: 0;
	}
	.row55{
		width: 60px;
		padding: 5px;
	}
	.row55 a {
	    border: 1px solid #C9C9C9;
	    display: block;
	    float: left;
	    font-size: 0;
	    height: 8px;
	    line-height: 0;
	    margin-top: 1px;
	    text-indent: -9999px;
	    width: 17px;
	}
	.row55 a.add {
	    background: url("/public/orderimg/icon_cart.gif") no-repeat scroll 6px -58px transparent;
	}
	.row55 a.cut {
	    background: url("/public/orderimg/icon_cart.gif") no-repeat scroll 6px -67px transparent;
	}
</style>

<body>
	<div class="main_frame">
    <div class="car_frame">
     
      <table width="100%" cellspacing="10" cellpadding="0" border="0">
        <tbody><tr>
          <td height="39"><img width="261" height="39" src="/public/orderimg/cart_title.jpg"></td>
          <td align="right" height="71"><img width="421" height="39" src="/public/orderimg/cart_show.jpg"></td>
        </tr>
      </tbody></table>
    </div>
    <div class="car_frame">
    <table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#c1c1c1">
      <tbody><tr>
        <td width="90" height="35" bgcolor="#e3e3e3"><div align="center">图书</div></td>
        <td bgcolor="#e3e3e3"><div align="center">图书名称</div></td>
        <td width="90" bgcolor="#e3e3e3"><div align="center">作者</div></td>
        <td width="80" bgcolor="#e3e3e3"><div align="center">数量</div></td>
        <td width="80" bgcolor="#e3e3e3"><div align="center">操作</div></td>
      </tr>
      #{list cars,as:'car' }
	      <tr>
	        <td align="center" height="90" bgcolor="#ffffff">
	        	<a target="_self" href="/show_${car?.getBoo()?.id }_book.html">
	        		<img width="51" height="69" border="0" src="${car?.getBoo()?.simage }"></a></td>
	        <td align="center" bgcolor="#ffffff"><a href="/show_${car?.getBoo()?.id }_book.html">${car?.getBoo()?.booName }</a></td>
	        <td align="center" bgcolor="#ffffff">${service.BookService.getAuthor(car?.getBoo()?.id)?.autrName}</td>
	        <td bgcolor="#ffffff" align="center" class="row55">
	          <!--[if IE 6]><div></div><![endif]-->
	          <input id="number${car?.getBoo()?.id }" onkeypress=" if((arguments[0] || window.event).keyCode==13) updateBook(${car?.getBoo()?.id });" onblur="updateBook(${car?.getBoo()?.id });" value="${car.count }" style="width:36px; height:19px; line-height:14px;float: left;" type="text" name="number">
	          <a class="add" title="数量加一" href="javascript:addBook(${car?.getBoo()?.id });">+</a>
	          <a class="cut" title="数量减一" href="javascript:reductionBook(${car?.getBoo()?.id });">-</a>
	        </td>
	        <td align="center" bgcolor="#ffffff">
	            <input type="button" style=" border:0px; background-color:#FFFFFF; cursor:pointer;" onclick="removeBook(${car?.getBoo()?.id })" value="删除">
	            <input type="button" style=" border:0px; background-color:#FFFFFF; cursor:pointer;" onclick="addSc(${car?.getBoo()?.id })" value="收藏">
	            </td>
	      </tr>
      #{/list}
      <tr>
        <td align="right" height="35" bgcolor="#e3e3e3" colspan="9">&nbsp;</td>
      </tr>
    </tbody></table>
    </div>
    <div class="car_frame">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
        <tbody><tr>
          <td height="35"><span class="gray">温馨提示：为了保证您及时购买到喜欢的商品，请您尽快完成订单提交，以便我们为您确认库存状态并及时配送。</span></td>
        </tr>
      </tbody></table>
    </div>
    <div class="car_frame">
      <table cellspacing="10" cellpadding="0" border="0" style="float:right;">
        <tbody>
	        <tr>
	          <td align="center" width="105" valign="bottom" height="80">
	          	<a target="_self" href="index.aspx"><img width="104" height="32" src="/public/orderimg/back_buy.jpg"></a></td>
	          <td align="center" width="165" valign="bottom">
	          	<a  href="/controllers/Order.order2"><img width="161" height="48" border="0" src="/public/orderimg/to_count.jpg"></a></td>
	        </tr>
      	</tbody>
     </table>
    </div>
    <div style="clear: both;"></div>
    <div class="car_frame">
    <table width="100%" cellspacing="1" cellpadding="0" border="0" bgcolor="#c1c1c1">
      <tbody><tr>
        <td width="90" height="35" bgcolor="#e3e3e3"><div align="center">图书</div></td>
        <td bgcolor="#e3e3e3"><div align="center">图书名称</div></td>
        <td width="90" bgcolor="#e3e3e3"><div align="center">作者</div></td>
        <td width="80" bgcolor="#e3e3e3"><div align="center">数量</div></td>
        <td width="80" bgcolor="#e3e3e3"><div align="center">操作</div></td>
      </tr>
      #{list scj,as:'car' }
	      <tr>
	        <td align="center" height="90" bgcolor="#ffffff">
	        	<a target="_self" href="/show_${car?.getBoo()?.id }_book.html">
	        		<img width="51" height="69" border="0" src="${car?.getBoo()?.simage }"></a></td>
	        <td align="center" bgcolor="#ffffff"><a href="/show_${car?.getBoo()?.id }_book.html">${car?.getBoo()?.booName }</a></td>
	        <td align="center" bgcolor="#ffffff">${service.BookService.getAuthor(car?.getBoo()?.id)?.autrName}</td>
	        <td bgcolor="#ffffff" align="center" class="row55">
	          <!--[if IE 6]><div></div><![endif]-->
	          ${car.count }
	        </td>
	        <td align="center" bgcolor="#ffffff">
	            <input type="button" style=" border:0px; background-color:#FFFFFF; cursor:pointer;" onclick="jrCarBook(${car?.getBoo()?.id })" value="放入借阅车">
	        </td>
	      </tr>
      #{/list}
      <tr>
        <td align="right" height="35" bgcolor="#e3e3e3" colspan="9">&nbsp;</td>
      </tr>
    </tbody></table>
    </div>
  </div>
<script type="text/javascript">
	var co = ${hky };
	var inp;
	function updateBook(id){
		inp = $("#number"+id);
		var oldVal = Number(inp.val());
		var allNumber = $("input[name='number']");
		var size = 0;
		allNumber.each(function(i,o){
			size += Number(o.value);
		});
		size -= Number(inp.val());
		if(Number(inp.val())+size > co){
			aduAlert("超过当前借阅卡等级的借书总数量,你总共还可以借阅<font color=red><b>"+co+"</b></font>本书",null,function(){
				inp.val(oldVal);
			});
		}else if(inp.value <= 0){
			aduConfirm("确认移除当前书籍","提示",function(fag){
				if(fag){
					removeBook(id);
				}
			});
		}
		
		$.ajax({
			url:'/controllers/Order.editCar',
			type:'post',
			data:{booid:id,size:inp.val()},
			success:function(e){
				
			}
		});
	}
	function removeBook(id){
		aduConfirm("确认移除当前书籍","提示",function(fag){
			if(fag){
				$.ajax({
					url:'/controllers/Order.removeBook',
					type:'post',
					data:{booid:id},
					success:function(e){
						window.location.reload();
					}
				});
			}
		});
	}
	function addBook(id){
		inp = $("#number"+id);
		var oldVal = Number(inp.val());
		inp.val(oldVal+1);
		var allNumber = $("input[name='number']");
		var size = 0;
		allNumber.each(function(i,o){
			size += Number(o.value);
		});
		size -= Number(inp.val());
		if(Number(inp.val())+size > co){
			aduAlert("超过当前借阅卡等级的借书总数量,你总共还可以借阅<font color=red><b>"+co+"</b></font>本书",null,function(){
				inp.val(oldVal);
			});
		}
	}
	function reductionBook(id){
		inp = $("#number"+id);
		inp.val(Number(inp.val()-1));
		if(Number(inp.val()) <= 0){
			aduConfirm("确认移除当前书籍","提示",function(fag){
				if(fag){
					removeBook(id);
				}else{
					inp.val(1);
				}
			});
		}
	}
	
	function goUpdate(id){
	
	}
	
	function addSc(id){
		aduConfirm("确认将书籍加入收藏吗","提示",function(fag){
			if(fag){
				$.ajax({
					url:'/controllers/Order.addScBook',
					type:'post',
					data:{booid:id},
					success:function(e){
						window.location.reload();
					}
				});
			}
		});
	}
	
	function jrCarBook(id){
		aduConfirm("确认将书籍加入借阅车吗","提示",function(fag){
			if(fag){
				$.ajax({
					url:'/controllers/Order.jrCarBook',
					type:'post',
					data:{booid:id},
					success:function(e){
						window.location.reload();
					}
				});
			}
		});
	}
</script>
  